package com.design.pattern.strategy.processor;

import com.design.pattern.strategy.Order;
import com.design.pattern.strategy.handler.Pay;

import java.util.List;

/**
 * @author 王霄
 * @date 2022/3/9 21:54
 */
public class DefaultPayProcessor implements PayProcessor {

    private final List<Pay> payList;

    public DefaultPayProcessor(List<Pay> payList) {
        this.payList = payList;
    }

    @Override
    public void process(Order order) {
        Pay pay = payList.stream()
                .filter(p -> order.getFrom().equals(p.getOrderType().getFrom()))
                .findFirst()
                .orElseThrow(() -> new RuntimeException("未知的订单类型: " + order.getFrom()));
        pay.pay(order);
    }
}
